package com.itheima.dao;

import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Select("select * from user where username=#{username} and password=#{password}")
    User login(User u);

    @Select("select count(*) from t_user ")
    int queryTotalCount();
    @Select("select * from t_user limit #{startIndex},#{pageSize} ")
    List<User> getUserByPage(
            @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);
    // 添加成功后,将自增的主键返回
    @Insert("insert into t_user (username,password,email,remark) values(#{username},#{password},#{email},#{remark})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    void addUser(User user);

    @Insert("insert into t_user_role values(#{userId},#{roleId})")
    void addUserAndRole(@Param("userId") int userId,@Param("roleId") String roleId);
}
